import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';

class SwitchViewPage extends StatefulWidget {
  const SwitchViewPage({Key? key}) : super(key: key);

  @override
  _MyHomePageState createState() => _MyHomePageState();
}

class _MyHomePageState extends State<SwitchViewPage> {
  final List<String> _values = ['Item 1', 'Item 2', 'Item 3', 'Item 4', 'Item 5'];

  @override
  Widget build(BuildContext context) {
    return Scaffold(
        appBar: AppBar(),
        body: 

        ListView.separated(
            itemCount: _values.length,
            padding: const EdgeInsets.all(5.0),
            separatorBuilder: (context, index) => const Divider(
                  color: Colors.black,
                ),
            itemBuilder: (context, index) {
              return draggable(index);
            }),
        );
  }

  Dismissible dismissible(int index) {
    return Dismissible(
      key: Key('item ${_values[index]}'),
      onDismissed: (DismissDirection direction) {
        if (direction == DismissDirection.startToEnd) {
          if (kDebugMode) {
            print("Selected Item");
          }
        } else {
          if (kDebugMode) {
            print('Delete item');
          }
        }

        setState(() {
          _values.removeAt(index);
        });
      },
      child: ListTile(
        leading: const Icon(Icons.email, size: 50),
        title: Text(_values[index]),
      ),
    );
  }

  Draggable draggable(int index) {
    return Draggable(
      child: ListTile(
        leading: const Icon(Icons.email, size: 50),
        title: Text(_values[index]),
      ),
      childWhenDragging: const Text("滑动"),
      feedback: const Text("菜单"),
      // key: Key('item ${_values[index]}'),
      // onDismissed: (DismissDirection direction) {
      //   if (direction == DismissDirection.startToEnd) {
      //     print("Selected Item");
      //   } else {
      //     print('Delete item');
      //   }

      //   setState(() {
      //     _values.removeAt(index);
      //   });
      // },
      // child: ListTile(
      //   leading: const Icon(Icons.email, size: 50),
      //   title: Text(_values[index]),
      // ),
    );
  }
}
